<template>
  <div class="outline__list">
    <el-tree
      class="custom-outline-tree"
      style="max-width: 600px; height: 75vh; overflow-y: auto;"
      :data="headings"
      :props="defaultProps"
      node-key="id"
      :default-expand-all="true"
      :expand-on-click-node="false"
      highlight-current
      @node-click="handleHeadingClick"
    />
  </div>
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia'
import  {useEditorStore} from '@/stores/editStore'
const editorStore = useEditorStore()
const { headings } = storeToRefs(editorStore)
/**
 * 左侧区域
 */
const handleHeadingClick = (data:any) => {
 editorStore.setActiveHeading(data)
}
const defaultProps = {
  children: 'children',
  label: 'text',
  disabled: false,
}
</script>

<style scoped lang="scss">

.outline__list {
  background: transparent;
  padding: 0;
  width: 100%;
  min-width: 200px;
  box-sizing: border-box;
  overflow: hidden;
}

/* el-tree整体样式 */
.custom-outline-tree {
  background: transparent;
  color: #222;
  --el-tree-node-hover-bg-color: #e3e8ef;
}

/* 节点文本颜色和缩进 */
.custom-outline-tree :deep(.el-tree-node__content) {
  color: #222;
  border-radius: 6px;
  min-height: 36px;
  line-height: 36px;
  padding: 0 8px;
  margin: 2px 0;
  transition: background 0.2s, color 0.2s, border 0.2s;
  border: 1.5px solid transparent;
}

/* 一级标题加粗 */
.custom-outline-tree :deep(.el-tree-node__content > .el-tree-node__label) {
  font-weight: 400;
  color: #222;
  font-size: 18px;
}

/* 二级及以下缩进和字体 */
.custom-outline-tree :deep(.el-tree-node__children) {
  padding-left: 8px !important;
  font-weight: normal;
}

/* hover效果 */
.custom-outline-tree :deep(.el-tree-node__content):hover {
  background: #e3e8ef !important;
  color: #1976d2 !important;
  border: 1.5px solid #4e9cff;
  font-weight: bold;
}

/* 选中高亮 */
.custom-outline-tree :deep(.el-tree-node.is-current > .el-tree-node__content) {
  background: #e3e8ef !important;
  color: #1976d2 !important;
  border: 1.5px solid #4e9cff;
  font-weight: bold;
}

/* 折叠箭头颜色 */
.custom-outline-tree :deep(.el-tree-node__expand-icon) {
  color: #8a919f;
  font-size: 28px;
}

/* 隐藏 el-tree 默认的连接线 */
.custom-outline-tree :deep(.el-tree-node__children) {
  border-left: none !important;
}
</style>
